unit LT_Contact;

interface
Uses Windows, PluginElems;
type
  TLT_Contact=class
  private
  FUID:TLT_UID;
  FTitle:PWideChar;
  FFirstName:PWideChar;
  FMiddleName:PWideChar;
  FLastName:PWideChar;
  FGender:Integer;
  FCompanyName:PWideChar;
  FParentUID:TLT_UID;
  FCreateDate:TDateTime;
  FBirthDate:TDateTime;
  function isExists():Boolean;
  public
  constructor Create(uid:TLT_UID);
  //parent
  function GetParentUID():TLT_UID;
  procedure SetParentUID(parentUID:TLT_UID);
  //title
  function GetTitle():PWideChar;
  procedure setTitle(title:PWideChar);
  //first name
  function getFirstName():PWideChar;
  procedure setFirstName(name:PWideChar);
  //middle name
  function GetMiddleName():PWideChar;
  procedure SetMiddleName(name:PWideChar);
  //last name
  function GetLastName():PWideChar;
  procedure SetLastName(name:PwideChar);
  //gender
  function getGender():Integer;
  procedure setGender(value:Integer);
  //company Name
  function GetCompanyName():PWideChar;
  procedure SetCompanyName(name:PWideChar);

  function getCreateDate():TDateTime;
  procedure setCreateDate(date:TDateTime);
  //children
  function GetChildsCount():Integer;
  function GetChildUID(n:Integer):TLT_UID;
  //communications
  function GetCommunicationsCount():Integer;
  procedure GetCommunication(n:Integer; var comType:PWideChar; var comValue:PWideChar; var comment:PWideChar);
  //birthdate
  function GetBirthDate():TDateTime;
  procedure SetBirthDate(date:TDateTime);
  //photo
  function GetPhoto():HBitmap;
  procedure SetPhoto(bmp:HBitmap);
  //operations
  function Save():TLT_UID;
  property uid:TLT_UID read FUID;
  property title:PWideChar read getTitle write setTitle;
  property exists:Boolean read isExists;
  property firstName:PWideChar read getFirstName write setFirstName;
  property middleName:PWideChar read getMiddleName write setMiddleName;
  property lastName:PWideChar read getLastName write setLastName;
  property gender:Integer read getGender write setGender;
  property companyName:PWideChar read GetCompanyName write SetCompanyName;
  property parentUID:TLT_UID read getParentUID write setParentUID;
  end;
implementation

{ TLT_Contact }

constructor TLT_Contact.Create(uid: TLT_UID);
begin
FUID:=uid;
end;

function TLT_Contact.isExists: Boolean;
begin
Result:=(uid<>nil) and (WideCharToString(uid)<>'');
end;

function TLT_Contact.GetTitle: PWideChar;
begin
if exists then
  Result:=AddinLT_Contact_GetTitle(uid)
else
  Result:=FTitle;
end;


procedure TLT_Contact.setTitle(title: PWideChar);
begin
if exists then
  AddinLT_Contact_SetTitle(uid,title)
else
  FTitle:=title;
end;

function TLT_Contact.getFirstName: PWideChar;
begin
if exists then
  Result:=AddinLT_Contact_GetFirstName(uid)
else
  Result:=FFirstName;
end;

procedure TLT_Contact.setFirstName(name: PWideChar);
begin
if exists then
  AddinLT_Contact_SetFirstName(uid,name)
else
  FFirstName:=name;
end;

function TLT_Contact.GetMiddleName: PWideChar;
begin
if exists then
  Result:=AddinLT_Contact_GetMiddleName(uid)
else
  Result:=FMiddleName;
end;

procedure TLT_Contact.SetMiddleName(name: PWideChar);
begin
if exists then
  AddinLT_Contact_SetMiddleName(uid, name)
else
  FMiddleName:=name;
end;

function TLT_Contact.GetLastName: PWideChar;
begin
if exists then
  Result:=AddinLT_Contact_GetLastName(uid)
else
  Result:=FLastName;
end;

procedure TLT_Contact.SetLastName(name: PwideChar);
begin
if exists then
  AddinLT_Contact_SetLastName(uid, name)
else
  FLastName:=name;
end;

function TLT_Contact.getGender: Integer;
begin
if exists then
  Result:=AddinLT_Contact_GetGender(uid)
else
  Result:=FGender;
end;

procedure TLT_Contact.setGender(value: Integer);
begin
if exists then
  AddinLT_Contact_SetGender(uid, value)
else
  FGender:=value;
end;

function TLT_Contact.GetCompanyName: PWideChar;
begin
if exists then
  Result:=AddinLT_Contact_GetCompanyName(uid)
else
  Result:=FCompanyName;
end;

procedure TLT_Contact.SetCompanyName(name: PWideChar);
begin
if exists then
  AddinLT_Contact_SetCompanyName(uid, name)
else
  FCompanyName:=name;
end;

function TLT_Contact.GetParentUID: TLT_UID;
begin
if exists then
  Result:=AddinLT_Contact_GetParentUID(uid)
else
  Result:=FParentUID;
end;

procedure TLT_Contact.SetParentUID(parentUID: TLT_UID);
begin
if exists then
  AddinLT_Contact_SetParentUID(uid, parentUID)
else
  FParentUID:=parentUID;
end;

function TLT_Contact.GetChildsCount: Integer;
begin
Result:=AddinLT_Contact_GetChildsCount(uid);
end;

function TLT_Contact.GetChildUID(n: Integer): TLT_UID;
begin
Result:=AddinLT_Contact_GetChildUID(uid, n);
end;

function TLT_Contact.Save: TLT_UID;
begin
if exists then
  AddinLT_Contact_SaveChanges(uid)
else
begin
  FUID:=AddinLT_Contact_Insert('',getParentUId(),getTitle(),getCreateDate());

  if uid<>nil then
  begin
    setFirstName(FFirstName);
    SetMiddleName(FMiddleName);
    SetLastName(FLastName);
    SetBirthDate(FBirthDate);
    Save();
  end;
end;
end;

function TLT_Contact.getCreateDate: TDateTime;
begin
if exists then
  Result:=AddinLT_Contact_GetDateCreate(uid)
else
  Result:=FCreateDate;
end;


procedure TLT_Contact.setCreateDate(date: TDateTime);
begin
FCreateDate:=date;
end;

function TLT_Contact.GetCommunicationsCount: Integer;
begin
Result:=AddinLT_Contact_GetCommunicationsCount(uid);
end;

procedure TLT_Contact.GetCommunication(n: Integer; var comType, comValue,
  comment: PWideChar);
begin
AddinLT_Contact_GetCommunication(uid,n,comType,comValue,comment);
end;

function TLT_Contact.GetBirthDate: TDateTime;
begin
if exists then
  Result:=AddinLT_Contact_GetBirthDate(uid)
else
  Result:=FBirthDate;
end;

procedure TLT_Contact.SetBirthDate(date: TDateTime);
begin
if exists then
  AddinLT_Contact_SetBirthDate(uid,date)
else
  FBirthDate:=date;
end;

function TLT_Contact.GetPhoto: HBitmap;
begin
Result:=AddinLT_Contact_GetFoto(uid);
end;

procedure TLT_Contact.SetPhoto(bmp: HBitmap);
begin
AddinLT_Contact_SetFoto(uid, bmp);
end;

end.
 